// JavaScript Document

var AntzBase = {
    
    confirmSubmit : function (question, yesFunc, noFunc){
        if(confirm(question)){
            setTimeout(yesFunc, 100);
        }else{
            setTimeout(noFunc, 100);
        };
    },
    
    customConfirmSubmit : function (func, yesFunc, noFunc){
        return eval(func+"(\""+yesFunc+"\", \""+noFunc+"\")");
    },
    
    submitForm : function (id){
        if(document.getElementById(id) && document.getElementById(id).submit)
            document.getElementById(id).submit();
    },
    
    startLoadingProgress  : function(idname){
        if(!document.getElementById(idname)) return;
        else var el = document.getElementById(idname);
        var img = document.createElement('img');
        img.src = AntzBaseUrl+'/images/site/icons/loading.gif';
        img.className = 'loadinggif';
        img.id = idname + '_loading';
        el.parentNode.appendChild(img);
        return;
        var span = document.createElement('span');
        span.id = idname + '_loading';
        span.className = 'loadingProgress';
        span.innerHTML = 'Loading';
        el.parentNode.appendChild(span);
        AntzBase.loadingProgressInterval = window.setInterval('AntzBase.incrementLoadingProgress("'+span.id+'")', 500);
    },
    
    toggleClipboard : function(){
        if(!document.getElementById('clipboardContent'))return;
        var el = document.getElementById('clipboardContent');
        if(el.style.display == 'block') el.style.display = 'none';
        else el.style.display = 'block';
    },
    
    incrementLoadingProgress : function(idname){
     
        if(!document.getElementById(idname)) return;
        else var el = document.getElementById(idname);
      
        var text = el.innerHTML;
        switch(text){
            case 'Loading':
                el.innerHTML = 'Loading.';
            break;
            case 'Loading.':
                el.innerHTML = 'Loading..';
            break;
            case 'Loading..':
                el.innerHTML = 'Loading...';
            break;
            case 'Loading...':
                el.innerHTML = 'Loading';
            break;
        };
    },
    
    stopLoadingProgress : function(idname){
        if(!document.getElementById(idname))return;
        else var el = document.getElementById(idname);
        if (!document.getElementById(idname+'_loading')) return;
        else var span = document.getElementById(idname+'_loading');
        span.parentNode.removeChild(span);
        return;
        window.clearInterval(AntzBase.loadingProgressInterval);
    },
    
    clearSuccess : function(){
        if(document.getElementById('AntzSuccessMsg'))    
            document.getElementById('AntzSuccessMsg').style.display = 'none';
    },
    
    clearError : function(){
        if(document.getElementById('AntzErrorMsg'))
            document.getElementById('AntzErrorMsg').style.display = 'none';
    },
    
    disableSubmitButtons : function(){
        var ins = document.getElementsByTagName('input');
        for(var i=0; i<ins.length; i++){
            if(ins[i].type == 'submit'){
                ins[i].disabled = true;
            };
        };
    },
    
    /**  
     *  Get the current selected KEY of a drop-menu. Pass the element reference
     *  Eg:
     *  var el = document.getElementById('myId');
     *  var key = AntzBase.dom_dropMenuSelectionKey(el);            
     *  alert('you have selected '+$key);
     */
     
    dom_dropMenuSelectionKey : function (el)
    
    {
        if(document.getElementById(el)) var el = document.getElementById(el);
        if(el.options && el.options[el.selectedIndex])
        return el.options[el.selectedIndex].value;
    },
    
    /**
     * Creates and returns a compatible Ajax Object depending on the browser    
     * 
     */          

    createAjax : function(){
        if (window.XMLHttpRequest) { 
            return new XMLHttpRequest();
        } else if (window.ActiveXObject) { 
            return new ActiveXObject("Microsoft.XMLHTTP");
        };
    }
    
};// end AntzBase = {}


/**
 *  Global functions follow 
 */


/**
*
* Javascript trim, ltrim, rtrim
* http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
} 


/**
 *  retrieved from http://www.thescripts.com/forum/thread93546.html 26 jan 08
 */ 

function addEvent(elementObject, eventName, functionObject)
{
if(document.addEventListener)
elementObject.addEventListener(eventName,
function (evt) {
functionObject(elementObject, evt)
}, false);
else
if(document.attachEvent)
elementObject.attachEvent("on" + eventName,
function () {
functionObject(elementObject);
}
)
}

/**
 *  retrieved from http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_nl2br/ 26 jan 08
 */ 
function nl2br( str ) {
    // http://kevin.vanzonneveld.net
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');
    // *     returns 1: 'Kevin<br/>van<br/>Zonneveld'
 
    return str.replace(/([^>])\n/g, '$1<br/>');
}



